﻿namespace Digitalmes.Application.Sys.Menus.Commands;

/// <summary>
/// 创建菜单命令。
/// </summary>
public record CreateMenuCommand(SysMenuDto Menu) : IRequest<IResult<bool>>;

internal sealed class CreateMenuCommandHandler(IRepository<SysMenu> repo) : IRequestHandler<CreateMenuCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(CreateMenuCommand request, CancellationToken cancellationToken)
    {
        var menu = request.Menu.Adapt<SysMenu>();
        var ok = await repo.InsertAsync(menu, cancellationToken);
        return Result.From(ok);
    }
}
